	<!--  -->
	<template>
	<div>
		<Card>
			<div slot="title" >
				<Button v-if="btnp.sbwxiu_lrbx" @click="handleClickAddForm" class="zh-hollow" type="primary" icon="plus-round">录入报修单</Button>
			</div>
			<Form :model="formItem" :label-width="70">
				<Row :gutter="10" type="flex"  align="middle"  >
				<Col span="8">
					<FormItem label="维修单">
						<Input v-model="formItem.orderNumber" placeholder="单号/报修手机号" clearable></Input>
					</FormItem>
				</Col>
				<Col span="8" v-if="user_type!=='01'">
					<FormItem label="客户">
						<Select v-model="formItem.customerUuid" filterable @on-change="searchCustomerChange">
							<Option  v-for="item in moreCustomerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
						</Select>
					</FormItem>
				</Col>
				<Col span="8">
					<FormItem label="机构">
						<Input @on-focus="s_tree=true;" :disabled="formItem.customerUuid.length<=0||formItem.customerUuid=='全部'" v-model="formItem.instName" placeholder="请选择机构" readonly></Input>
						<!-- <Select :disabled="!formItem.customerUuid||formItem.customerUuid=='全部'" v-model="formItem.instuuid" filterable>
							<Option  v-for="item in moreMechanismList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
						</Select> -->
					</FormItem>
				</Col>
				<Col span="8">
					<FormItem label="进度">
						<Select v-model="formItem.state" >
							<Option  v-for="item in moreProgressList" :value="item.state" :key="item.state">{{ item.desc }}</Option>
						</Select>
					</FormItem>
				</Col>
				<Col span="8">
					<FormItem label="预警">
						<Select v-model="formItem.warningOvertime" >
							<Option  v-for="item in moreWarningList" :value="item.state" :key="item.state">{{ item.desc }}</Option>
						</Select>
					</FormItem>
				</Col>
				<Col span="12">
					<FormItem label="报修时间">
						<DatePicker v-model="search.timeRange" format="yyyy-MM-dd HH:mm" type="datetimerange" placement="bottom-end" placeholder="请选择开始和结束时间"></DatePicker>
					</FormItem>
				</Col>
				<Col span="12"  >
					<FormItem label="所在地">
						<Cascader change-on-select v-model="search.location" placeholder="请选择省市区" :data="areasData" ></Cascader>
					</FormItem>
				</Col>
				
				</Row>
				<Row :gutter="10" >
				<Col span="8" offset="16"  style="text-align:right;">
					<Button class="zh-hollow" type="primary" icon="ios-search-strong" @click="handleClickgetTable">搜索</Button>
					<a style="margin-left:25px;" v-if="btnp.sbwxiu_dc" :href="downLoadUrl" target="_blank"><Button  class="zh-hollow" type="warning"  > 导出EXCEL </Button></a>
				</Col>
				
				</Row>
			</Form>
		</Card>
		<Card style="margin-top:10px;" :padding="0">
			<Table :loading="loading" border :columns="columns" :data="data"></Table>
			<Page  :total="total" show-total show-sizer :current.sync="formItem.pageNumber" @on-change="pageChange" @on-page-size-change="pageSizeChange"></Page>
		</Card>
		<!-- 进度对话框 -->
		<progressModal 
		:zhmodel="modal_repaire_progress" 
		title="维修进度" 
		:totalTime="repaire_progress_details.totalTime"
		:columns="modal_columns"
		:data="repaire_progress_details.data"
		@change="change"
		>
		</progressModal>
		<!-- 录入报修单对话框 -->
		<Modal  title="录入报修"  v-model="modal_add_declaration_form"  :mask-closable="false"  >
			<Form   :model="addForm" :label-width="80" style="padding:20px;">
				<FormItem label="联系电话*" class="zh-radio-input">
				<RadioGroup v-model="addForm.radio" vertical @on-change="radioChange">
						<Radio label="mobile" style="marginBottom:10px;">手机号</Radio>
						<Radio label="landline">座机号</Radio>
				</RadioGroup>
				<div>
					<Input  @on-change="mobileChange"  style="marginBottom:10px;" :maxlength="11" :disabled="addForm.radio!=='mobile'" v-model="addForm.mobile" placeholder="手机号"></Input>
					<div class="landline-input-container">
					<Input v-model="addForm.landline1" :disabled="addForm.radio==='mobile'" placeholder="区号"></Input>-
					<Input v-model="addForm.landline2" :disabled="addForm.radio==='mobile'" placeholder="座机号"></Input>-
					<Input v-model="addForm.landline3" :disabled="addForm.radio==='mobile'" placeholder="分机号"></Input>
					</div>
				</div>
				</FormItem>
				<FormItem label="报修人*">
				<Input :readonly="repaireReadonly" v-model="addForm.name" :maxlength="5" ></Input>
				</FormItem>
				<FormItem label="所在地*">
						<Input v-if="repaireReadonly" :readonly="repaireReadonly" v-model="addForm.locations" :maxlength="5" ></Input>
						<Cascader v-else change-on-select  @on-change="repaireCascaderChange" v-model="addForm.location" placeholder="请选择省市区" :data="areasData" ></Cascader>
				</FormItem>
				<FormItem label="客户*" v-if="user_type!=='01'">
						<Input v-if="repaireReadonly" :readonly="repaireReadonly" v-model="addForm.customerName" :maxlength="5" ></Input>
						<Select @on-change="formCustomerChange"  v-else :disabled="!addForm.location[0]" v-model="addForm.customerUuid" filterable>
							<Option  v-for="item in customerList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
						</Select>
				</FormItem>
				<FormItem label="报修机构*">
					<Input v-if="user_type!=='01'" @on-focus="f_tree=true;" :disabled="!addForm.location[0]||(addForm.customerUuid.length<=0)" v-model="addForm.instname" placeholder="请选择机构" readonly></Input>
					<Input v-else @on-focus="f_tree=true;" :disabled="!addForm.location[0]" v-model="addForm.instname" placeholder="请选择机构" readonly></Input>
					<!-- <Select v-if="user_type!=='01'" :disabled="!addForm.location[0]||(addForm.customerUuid.length<=0)" v-model="addForm.instUuid" filterable>
						<Option  v-for="item in mechanismList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
					</Select>
					<Select v-else :disabled="!addForm.location[0]" v-model="addForm.instUuid" filterable>
						<Option  v-for="item in mechanismList" :value="item.uuid" :key="item.uuid">{{ item.name }}</Option>
					</Select> -->
				</FormItem>
				<FormItem label="设备编号">
				<Input v-model="addForm.code" ></Input>
				</FormItem>
				<FormItem label="故障类型">
						<Select v-model="addForm.faultTypeUuid" filterable>
							<Option  v-for="item in faultTypeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
						</Select>
				</FormItem>
				<FormItem label="故障描述*">
						<Input :maxlength="200" type="textarea" :autosize="{minRows: 2,maxRows: 5}" v-model="addForm.describe " ></Input>
				</FormItem>
			</Form>
			<div slot="footer">
				<div class="zh-flex zh-flex-5" >
					<Button @click="giveUpSaveReapaireForm" type="ghost">放弃操作</Button>
					<Button @click="saveReapaireForm" class="zh-hollow" type="primary" >保存</Button>
				</div>
			</div>
		</Modal>
		<!-- 配件更换对话框 -->
		<Modal title="配件更换" v-model="modal_parts_Detailed" class="no_footer_modal">
			<!-- <p slot="header" >配件更换</p> -->
			<div class="parts_Detailed_table" v-for="(item ,i) in parts_Detailed.detail " :key="i">
				<p slot="title">明细{{parseInt(i)+1}}</p>
				<Table :show-header='false'  :columns="parts_detaild_columns" :data="item"></Table>
			</div>
			<div style="textAlign:right;padding: 10px 20px;font-weight:700;">
				合计（元）：{{parts_Detailed.total}}
			</div>
		</Modal>
		<!-- 分配维修单 -->
		<distribuModal
		title="分配维修单"
		:zhmodel="modal_distribu_sheet"
		:optionsArrayF="proList.list1"
		:optionsArrayS="proList.list2"
		:formData="distribuForm"
		:data="distribu_sheet.records"
		@giveUpAction="giveUpActionClick"
		@change="distribuChange"
		@confirmDistribu="clickDistribuClick"
		>
		</distribuModal>
		<!-- 维修详情 -->
		<Modal title="维修详情"  v-model="modal_repaire_detail" class="no_footer_modal" >
			<!-- <p slot="header" >维修详情</p> -->
			<div class="detail-form">
				<div class="detail-form-item">
				<label>维修单号：</label>
				<span>{{repaire_details.order_number}}</span>
				</div>
				<div class="detail-form-item">
				<label>报修时间：</label>
				<span>{{repaire_details.startTime}}</span>
				</div>
				<div class="detail-form-item">
				<label>报修人：</label>
				<span>{{repaire_details.name}}</span>
				</div>
				<div class="detail-form-item">
				<label>联系电话：</label>
				<span>{{repaire_details.mobile}}</span>
				</div>
				<div class="detail-form-item" v-if="user_type!=='01'">
				<label>客户：</label>
				<span>{{repaire_details.customername}}</span>
				</div>
				<div class="detail-form-item">
				<label>所在地：</label>
				<span>{{repaire_details.location}}</span>
				</div>
				<div class="detail-form-item">
				<label>机构：</label>
				<span>{{repaire_details.inst_name}}</span>
				</div>
				<div class="detail-form-item">
				<label>报修设备：</label>
				<span v-if="!!repaire_details.equip" style="color:#2d8cf0">{{repaire_details.equip}}</span>
				</div>
				<div class="detail-img-video">
				<span>故障描述：</span>
				<p v-if="!!repaire_details.describe">{{repaire_details.describe}}</p>
				<div v-if="repaire_details.imageList.length>0" class="wrap">
					
					<img v-for="(item,i) in repaire_details.imageList"  :key="i" :src="item" @click="handleClickPicLook(item)" alt="">
				</div>
				<div v-if="!!repaire_details.video" class="wrap">
					<video poster="" @click="handleClickVideoPlay(repaire_details.video)"  :src="repaire_details.video"></video>
				</div>
				</div>
			</div>
			<div v-if="repaire_details.additional.length>0" class="detail-supplement">
				<div v-for="(item,i) in repaire_details.additional" :key="i" class="detail-supplement-item">
					<div class="spokesman">
						<Avatar icon="person" size="large" :src="!!item.image?domain+item.image:''" />
						<div style="marginLeft:10px;">
						<p>{{item.name}}</p>
						<p>{{item.created}}</p>
						</div>
					</div>
					<div class="speech" >
						<p v-if="item.describe.length>0">{{item.describe}}</p>
						<Row v-if="item.imageList.length>0" :gutter="15" type="flex" align="middle">
							<Col v-for="(child,index) in item.imageList" :key="index" span="6">
								<img :src="child" alt="" style="width:100%">
							</Col>
						</Row>
					</div>
				</div>
			</div>
			<div class="detail-other zh-flex zh-flex-3" v-if="!!repaire_details.remarks&&!!repaire_details.remarks.pro">
				<div class="detail-other-item"><label>运维人员：</label>{{repaire_details.proName}}</div>
				<div class="detail-other-item"><label>故障类型：</label>{{repaire_details.faultType}}</div>
				<div class="detail-other-item"><label>故障原因：</label>{{repaire_details.reason}}</div> 
				<div class="detail-other-item"><label>处理办法：</label>{{repaire_details.solve}}</div>
			</div>
			<div class="detail-other zh-flex zh-flex-3" v-if="!!repaire_details.skill_score">
				<div class="detail-other-item"><label>专业技能：</label>{{repaire_details.skill_score}}</div>
				<div class="detail-other-item"><label>响应速度：</label>{{repaire_details.speed_score}}</div>
				<div class="detail-other-item"><label>服务态度：</label>{{repaire_details.attitude_score}}</div>
				<!-- <div class="detail-other-item"><label>其他评价：</label>{{repaire_details.content}}</div> -->
			</div>
			<div class="detail-other zh-flex zh-flex-3" v-if="!!repaire_details.skill_score">
				
				<div class="detail-other-item" style="100%"><label>其他评价：</label>{{repaire_details.content}}</div>
			</div>
		</Modal>
		<!-- 查看图片 -->
		<Modal title="查看图片" v-model="look_pic_wrap.look_pic" class="no_footer_modal">
			<img style="width:100%;" :src="look_pic_wrap.src" alt="">
		</Modal>
		<!-- 看视频 -->
		<Modal title="查看视频" v-model="look_video_wrap.look_video" class="no_footer_modal">
			<video style="width:100%;" :src="look_video_wrap.src" controls alt=""></video>
		</Modal>
		<Modal title="选择机构" v-model="s_tree" @on-ok="confirmST" :mask-closable="false" >
			<div style="padding:15px 30px;">
				<Tree :data="s_tree_data"   @on-select-change="s_selectChange"></Tree>
			</div>
		</Modal>
		<Modal title="选择机构" v-model="f_tree" :loading="ft_load" @on-ok="confirmF" :mask-closable="false" >
			<div style="padding:15px 30px;">
				<Tree :data="f_tree_data"   @on-select-change="f_selectChange"></Tree>
			</div>
		</Modal>
	</div>
	</template>

	<script>
	import {url_repaire} from '@/libs/downLoadUrl'
	// import url from '@/libs/url.js'
	import accounting from 'accounting'
	import progressModal from '@/components/modal/progressModal.vue'
	import distribuModal from '@/components/modal/distribuModal.vue'
	import {
	getRepaireTableData,
	saveRepaire,
	saveFPZJ,
	revokeReapire,
	cancleRepaire,
	completeRepaire
	} from '@/libs/post.js'
	import {
	getWarningTree,
	getBankOrg,
	getEquipInfo,
	getUserInfoByMobile,
	getCustomerListByLocation,
	getRepaireDetails,
	tableToExcelRepaire,
	getRepaireProgress,
	getRepaireProgressTotalTime,
	getpurchase,
	getRecords,
	getFPPros,
	getOrgTree
	} from '@/libs/get.js'
	import util from '@/libs/util'
	export default {
	name:'repaire',
	components:{
		progressModal,
		distribuModal
	},
	data(){
		return {
			ft_load:true,
			f_select_op:[],
			f_tree_data:[],
			f_tree:false,
			s_select_op:[],
			s_tree_data:[],
			s_tree:false,
			domain:this.$store.state.app.domain,
			downLoadUrl:url_repaire,
			pro_uuid:'',
			btn:{
				sbwxiu_lrbx:false,
				sbwxiu_dc:false,
				sbwxiu_xq:false,
				sbwxiu_jd:false,
				sbwxiu_fp:false,
				sbwxiu_cx:false,
				sbwxiu_ch:false,
				sbwxiu_wc:false,
				sbwxiu_pjgh:false
			},
			btnp:{},
			fpCanClick:true,
			saveFormClick:true,
			repaireReadonly:false,
			canSave:false,
			/**判断是否是客户 */
			user_type:'',
			/**看视频 */
			look_video_wrap:{
				look_video:false,
				src:''
			},
			/** 查看图片*/
			look_pic_wrap:{
				look_pic:false,
				src:''
			},
			/**维修详情 */
			modal_repaire_detail:false,
			empty_repaire_details:{},
			repaire_details:{
				order_number:'',
				startTime:'',
				name:'',
				mobile:'',
				customername:'',
				location:'',
				inst_name:'',
				equip:'',
				describe:'',
				imageList:[],
				video:'',
				additional:[],
				proName:'',
				faultType:'',
				reason:'',
				rsolve:'',
				attitude_score:'',
				skill_score:'',
				speed_score:'',
				content:''
			},
			/**分配维修单 */
			modal_distribu_sheet:false,
			distribu_sheet:{
				records:[]
			},
			distribuForm:{
				uuid:'',
				candidate:'',
				content:''
			},
			proList:{
				list1:[],
				list2:[]
			},
			/**配件更换 */
			parts_detaild_columns:[
				{
				key:'name'
				},
				{
				key:'value'
				}
			],
			parts_Detailed:{
				total:'',
				detail:[]},
			modal_parts_Detailed:false,
			/** 录入报修单*/
			addForm:{
				userUuid:'',
				radio:'mobile',
				name:'',
				mobile:'',
				landline1:'',
				landline2:'',
				landline3:'',
				province:'',
				city:'',
				district:'',
				locations:'',
				location:[],
				customerUuid:'',
				customerName:'',
				instname:'',
				instUuid:'',
				code:'',
				faultTypeUuid:'',
				describe:'',
				equip_uuid:'',
			},
			modal_add_declaration_form:false,
			/**进度 */
			repaire_progress_details:{
				totalTime:'',
				data:[]
			},
			modal_columns:[
				{
				key:'action',
				align:'center',
				title:'操作'
				},
				{
				key:'time',
				align:'center',
				title:'时间'
				},
				{
				key:'time_consuming',
				align:'center',
				title:'耗时'
				},
				{
				key:'operator',
				align:'center',
				title:'操作人'
				},
				{
				key:'remarks',
				align:'center',
				title:'备注'
				}
			],
			modal_repaire_progress:false,


			/**已完成 */
			loading:true,
			total:0,
			search:{
				timeRange:[],
				location:[]
			},
			formItem:{
				orderNumber:'',
				customerUuid:'全部',
				instuuid:'',
				instName:'',
				state:'全部',
				warningOvertime:'全部',
				province:'',
				city:'',
				district:'',
				startTime:'',
				endTime:'', 
				pageSize:10,
				pageNumber:1
			},
			customerList:[],
			moreCustomerList:[{uuid:'全部',desc:'全部'}],
			mechanismList:[{uuid:'',desc:''}],
			moreMechanismList:[{uuid:'全部',desc:'全部'}],
			progressList:[],
			moreProgressList:[{state:'全部',desc:'全部'}],
			warningList:[],
			moreWarningList:[{state:'全部',desc:'全部'}],
			faultTypeList:[
				{
				value:'a5107676-8633-11e6-b59a-288023a1',
				label:'硬件故障'
				},
				{
				value:'a51260fb-8633-11e6-b59a-288023a1',
				label:'软件故障'
				},
				{
				value:'a5161f86-8633-11e6-b59a-288023a1',
				label:'系统故障'
				},
				{
				value:'a51724ab-8633-11e6-b59a-288023a1',
				label:'网络故障'
				},
				{
				value:'a518c4ac-8633-11e6-b59a-288023a1',
				label:'其他'
				}
			],
			areasData:this.$store.state.user.areaData,
			columns:[
				{
				key:'order_number',
				title:'维修单号',
				fixed:'left',
				minWidth:170
				},
				{
				key:'area',
				title:'所在地',
				minWidth:180
				},
				{
				key:'bank_name',
				title:'客户',
				minWidth:120
				},
				{
				key:'inst_name',
				title:'机构',
				minWidth:120
				},
				{
				key:'mobile',
				title:'报修人手机号',
				minWidth:120
				},
				{
				key:'created',
				title:'报修时间',
				minWidth:150
				},
				{
				key:'state_name',
				title:'进度',
				minWidth:80
				},
				{
				key:'warning_overtime_name',
				title:'预警',
				minWidth:90,
				render:(h,params)=>{
					let tcolor="#000";
					if(params.row.warning_overtime_name!=='正常'){
					tcolor='#EA7004';
					}
					return h('p',{
						style:{
						color:tcolor
						}
					},params.row.warning_overtime_name)
				
				}
				},
				{
				key:'action',
				title:'操作',
				align:'center',
				minWidth:200,
				fixed:'right',
				render:(h,params)=>{
					let uuid=params.row.uuid;
					//判断是否显示某些操作按钮
					let state=params.row.state;
					let dfp=this.btnp.sbwxiu_fp?state==="00"?'inline-block':'none':'none';
					let ch='none';
					if(this.btnp.sbwxiu_ch&&(state==="01"|state==="02"||state==="04"||state==="06")){
					ch='inline-block'
					}
				
					let close='none';
					if(state==="01"&&this.btnp.sbwxiu_wc){
					close='inline-block';
					}
					
					return h('div',[
					h('Button',{
						props:{
						type:'text',
						size:'small'
						},
						style:{
						color:'#2D8CF0',
						display:this.btnp.sbwxiu_xq?'inline-block':'none'
						},
						on:{
						click:()=>{
							
							this.getDetails(uuid);
						
						}
						}
					},'详情'),
					h('Button',{
						props:{
						type:'text',
						size:'small',
						display:this.btnp.sbwxiu_xq?'inline-block':'none'
						},
						style:{
						color:'#2D8CF0'
						},
						on:{
						click:()=>{
							this.clickProgressBtn(uuid);
						}
						}
					},'进度'),
					h('Button',{
						props:{
						type:'text',
						size:'small'
						},
						style:{
						color:'#2D8CF0',
						display:dfp
						},
						on:{
						click:()=>{
							this.distribuForm.uuid=uuid;
							this.fpModal(uuid,params.row.inst_uuid);
						}
						}
					},'分配'),
					h('Button',{
						props:{
						type:'text',
						size:'small'
						},
						style:{
						color:'#2D8CF0',
						display:this.btnp.sbwxiu_pjgh?params.row.partsChange==='1'?'iline-block':'none':'none'
						},
						on:{
						click:()=>{
							this.getpurchaseDatiles(uuid);
						}
						}
					},'配件更换'),
					h('Button',{
						props:{
						type:'text',
						size:'small'
						},
						style:{
						color:'#2D8CF0',
						display:ch
						},
						on:{
						click:()=>{
							
							let config={
							title:'撤回维修单',
							content:'将维修单撤回到待分配状态，可以重新分配。',
							okText:'撤回',
							cancelText:'放弃操作',
							onOk:()=>{
								this.clickrevokeReapire(uuid)
							}
							}
							this.$Modal.confirm(config)
						}
						}
					},'撤回'),
					h('Button',{
						props:{
						type:'text',
						size:'small'
						},
						style:{
						color:'#2D8CF0',
						display:close
						},
						on:{
						click:()=>{
							
							let config={
							title:'完成维修单',
							content:'管理员直接标记完成，该条报修单将无法记录维修细节。',
							okText:'标记完成',
							cancelText:'放弃操作',
							onOk:()=>{
								this.clickcompleteRepaire(uuid)
							}
							}
							this.$Modal.confirm(config)
						}
						}
					},'完成'),
					h('Button',{
						props:{
						type:'text',
						size:'small'
						},
						style:{
						color:'#EA0000',
						display:dfp,
						display:this.btnp.sbwxiu_cx?state==="00"?'inline-block':'none':'none'
						},
						on:{
						click:()=>{
							let config={
							title:'撤销维修单',
							content:'将维修单撤销后，维修任务结束，无法恢复。',
							okText:'撤销',
							cancelText:'放弃操作',
							onOk:()=>{
								this.clickcancleRepaire(uuid)
							}
							}
							this.$Modal.confirm(config)
						}
						}
					},'撤销')
					])
				}
				}
				
			],
			data:[]
		}
	},
	methods:{
		init(){
			let that=this;
			util.isCustomer(this);
			this.empty_repaire_details=JSON.parse(JSON.stringify(this.repaire_details));
			let timer;
			if(that.user_type!=='01'){
				timer=setInterval(()=>{
					if(that.$store.state.user.customer.length>0){
						that.moreCustomerList=[{name:'全部',uuid:'全部'},...that.$store.state.user.customer];
						clearInterval(timer)	
					}
				},500);
			}else{
				this.searchCustomerChange(this.userUuid);
			}
			
			// setTimeout(()=>{
			// 	// that.areasData=that.$store.state.user.areaData;
			// 	if(that.user_type!=='01'){
			// 	that.moreCustomerList=[{name:'全部',uuid:'全部'},...that.$store.state.user.customer];
			// 	}
			// },5000);
			// if(this.user_type=='01'){
			// 	this.newSearchCustomerChange(this.userUuid,'search');	
			// }  
		},
		async getFormInstTree(value,p,c,d){
			this.addForm.instUuid='';
			this.addForm.instname='';
			this.f_select_op=[];
			if(value!==''){
				let res=await getOrgTree(value,p,c,d);
				let response=res.data;
				if(response.code===200){
					this.f_tree_data=util.tree([response.data]);
				}else{
					this.$Notice.error({
						title: '获取机构失败',
						desc:response.msg
					});
				}
			}
		},
		f_selectChange(selectarr){
			this.f_select_op=selectarr;
		},
		confirmF(){
			if(this.f_select_op.length>0){
				if(this.f_select_op[0].canChoose=='true'){
					this.addForm.instUuid=this.f_select_op[0].value;
					this.addForm.instname=this.f_select_op[0].title;
				}else{
					this.$Notice.error({
						desc:'请选择有效节点'
					});
					this.ft_load=false;
					let that=this;
					setTimeout(() => {
						that.ft_load=true;
					}, 200);
					return false
				}
				
			}else{
				this.addForm.instUuid='';
				this.addForm.instname='';
			}
			this.f_tree=false;
		},
		async getSearchInstTree(value){
			this.formItem.instuuid='';
			this.formItem.instName='';
			this.s_select_op=[];
			if(value!=='全部'){
				let res=await getOrgTree(value);
				let response=res.data;
				if(response.code===200){
					this.s_tree_data=util.tree([response.data]);
				}else{
					this.$Notice.error({
						title: '获取机构失败',
						desc:response.msg
					});
				}
			}
		},
		s_selectChange(selectarr){
			this.s_select_op=selectarr;
		},
		confirmST(){
			if(this.s_select_op.length>0){
				this.formItem.instuuid=this.s_select_op[0].value;
				this.formItem.instName=this.s_select_op[0].title;
			}else{
				this.formItem.instuuid='';
				this.formItem.instName='';
			}
		},
		radioChange(val){
			if(val==='mobile'){
				this.addForm.landline1='';
				this.addForm.landline2='';
				this.addForm.landline3='';
				
			}else{
			this.addForm.mobile='';
				
			}
		},
		searchCustomerChange(value){
			//this.newSearchCustomerChange(value,'search')
			this.s_select_op=[];
			this.getSearchInstTree(value);
		},
		// async newSearchCustomerChange(value,type){
		// 	if(value!=='全部'){
		// 		let res;
		// 		if(type=='search'){
		// 			res =await getBankOrg(value,'','','')
		// 		}else{
		// 			res =await getBankOrg(value,this.addForm.province,this.addForm.city,this.addForm.district)
		// 		}
		// 		if(res.status===200){
		// 			let response=res.data;
		// 			if(response.code===200){
		// 			if(type==='search'){
		// 				this.moreMechanismList=[{uuid:'全部',name:'全部'},...response.data]
		// 			}else if(type==='form'){
		// 				this.mechanismList=response.data
		// 			}
					
					
		// 			}else{
		// 				this.$Notice.error({
		// 					title: '请求出错',
		// 					desc:response.msg
		// 				});
		// 			}
		// 		}else{
		// 			this.$Notice.error({
		// 				title: '请求失败'
		// 			});
		// 		} 
		// 	}else{
		// 	this.formItem.instuuid='';
		// 	}
		// },
		pageSizeChange(size){
			//回到第一页
			this.formItem.pageNumber=1;
			this.formItem.pageSize=size;
			this.getTable();
		},
		pageChange(number){
			this.formItem.pageNumber=number;
			this.getTable();
		},
		handleClickgetTable(){
			this.formItem.pageNumber=1;
			this.getTable();
			
		},
		async getTable(){
			this.loading=true;
			let form=JSON.parse(JSON.stringify(this.formItem));
			for(let key in form){
				if(form[key]==='全部'){
				form[key]='';
				}
			}
			form.pro_uuid=this.pro_uuid;
			if(!!this.search.timeRange[0]&&this.search.timeRange.length>0){
				form.startTime=util.time1(this.search.timeRange[0]);
				form.endTime=util.time1(this.search.timeRange[1]);
			}else{
				form.endTime='';
				form.startTime='';
			}
			if(this.search.location.length>0&&!!this.search.location[0]){
				form.province=this.search.location[0];
				form.city=this.search.location[1];
				form.district=this.search.location[2];
			}else{
				form.province='';
				form.city='';
				form.district='';
			}
			let res=await getRepaireTableData(form);
			if(res.status===200){
				let response=res.data;
				if(response.code===200){
					
					this.total=response.data.total;
					this.data=response.data.rows
					this.loading=false;
					
					this.downLoadUrl=`${url_repaire}${util.pjArgu(form)}`;
				}else{
					this.$Notice.error({
						title: '请求出错',
						desc:response.msg
					});
				}
			}else{
				this.$Notice.error({
					title: '请求失败'
				});
			} 
		},
		async getSelectInfo(){
			let res=await getWarningTree();
			if(res.status===200){
				let response=res.data;
				if(response.code===200){
					this.progressList=response.data.states;
					this.warningList=response.data.warningOvertimeStates;
					this.moreProgressList=[{state:'全部',desc:'全部'},...response.data.states];
					this.moreWarningList=[{state:'全部',desc:'全部'},...response.data.warningOvertimeStates];
				}else{
					this.$Notice.error({
						title: '请求出错',
						desc:response.msg
					});
				}
			}else{
				this.$Notice.error({
					title: '请求失败'
				});
			} 

		},
		async getequipInfo(equip_code){
			let res=await getEquipInfo(equip_code);
			let response=res.data;
			if(response.code===200){
				if(!!response.data.equip_uuid){
				this.addForm.equip_uuid=response.data.equip_uuid;
				this.canSave=true;
				} 
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
			}
		},
		async  othervalidate(){
			let addForm=this.addForm;
			const reg = /^[\u4e00-\u9fa5]{2,5}$/;
			if(!reg.test(addForm.name)){
				this.$Notice.error({desc:'请输入报修人真实姓名'})
			}else{
				if(addForm.location.length<3||addForm.location[0].length<1){
					this.$Notice.error({desc:'请选择报修地区'})
				}else{
					if(this.user_type!='01'&&(addForm.customerUuid.lenght<=0||addForm.customerUuid=='')){
						this.$Notice.error({desc:'请选择报修客戶'})
					}else{
						if(!addForm.instUuid||addForm.instUuid==''){
							this.$Notice.error({desc:'请选择报修机构'})
						}else{
							if(!addForm.describe||addForm.describe==''){
								this.$Notice.error({desc:'描述故障'})
							}else{
								if(!!addForm.code&&addForm.code.length>0){
									await this.getequipInfo(addForm.code);
								}else{
									this.canSave=true;
								}
							}
						}
					}
				}
			}
		},
		resetAddform(){
			for(let key in this.addForm){
				if(key=="location"){
					this.addForm[key]=[]
				}else if(key=="radio"){
					this.addForm[key]="mobile"
				}else{
					this.addForm[key]=''
				}
			}
		},
		giveUpSaveReapaireForm(){
			this.modal_add_declaration_form=false;
			this.resetAddform();
		},
		async postRepaireForm(){
			if(this.canSave&&this.saveFormClick){
				this.saveFormClick=false;
				let {
					name,
					mobile,
					province,
					city,
					district,
					customerUuid,
					instUuid,
					code,
					faultTypeUuid,
					describe,
					equip_uuid
					}=this.addForm;
				if(this.addForm.radio!='mobile'){
					mobile=`${this.addForm.landline1}-${this.addForm.landline2}`;
					if(!!this.addForm.landline3||this.addForm.landline3.length>0){
						mobile=`${mobile}-${this.addForm.landline3}`
					}
				}
				let res=await saveRepaire({
					name,
					mobile,
					province,
					city,
					district,
					customerUuid,
					instUuid,
					code,
					faultTypeUuid,
					describe,
					equip_uuid});
				let response=res.data;
				if(response.code===200){
					this.canSave=false;
					this.saveFormClick=true;
					this.modal_add_declaration_form=false;
					this.resetAddform();
					this.$Notice.success({
						desc:'录入报修单已保存'
					})
					this.formItem={
						orderNumber:'',
						customerUuid:'全部',
						instuuid:'全部',
						state:'全部',
						warningOvertime:'全部',
						province:'',
						city:'',
						district:'',
						startTime:'',
						endTime:'', 
						pageSize:10,
						pageNumber:1
					};
					this.getTable();
				}else{
					this.canSave=false;
					this.saveFormClick=true;
					this.$Notice.error({
						title: '请求出错',
						desc:response.msg
					});
				}
			}
		},
		async saveReapaireForm(){
			let addForm=this.addForm;
			if(addForm.mobile==''&&addForm.landline1==''&&addForm.landline2==''){
				this.$Notice.error({desc:'手机号和座机号必填一项'})
			}else{
				if(addForm.radio==='mobile'){
					const reg=this.$store.state.app.mobileReg;
					if(!reg.test(addForm.mobile)){
						this.$Notice.error({desc:'手机号格式错误'})
					}else{
						//其他验证
						await this.othervalidate()
						await this.postRepaireForm()
					}
				}else{
					const reg1=/^0[0-9]{2,3}/;
					const reg2=/[2-9][0-9]{6,7}/;
					const reg3=/\d{2,4}/;
					if(!reg1.test(addForm.landline1)){
						this.$Notice.error({desc:'座机区号格式错误'})
					}else if(!reg2.test(addForm.landline2)){
						this.$Notice.error({desc:'座机号格式错误'})
					}else if(addForm.landline3!=''&&!reg3.test(addForm.landline3)){
						this.$Notice.error({desc:'分机号格式错误'})
					}else{
						await this.othervalidate()
						await this.postRepaireForm()
					}
				}
			} 
		},
		
		async mobileChange(e){
		
			if(this.addForm.mobile.length===11){
				let res=await getUserInfoByMobile(this.addForm.mobile);
				let response=res.data;
				if(response.code===200){
					if(!!response.data.province){
						this.addForm.locations=`${response.data.province} ${response.data.city} ${response.data.district}`
						this.addForm.location=[response.data.province,response.data.city,response.data.district];
						this.addForm.province=response.data.province;
						this.addForm.city=response.data.city;
						this.addForm.district=response.data.district;
						this.addForm.customerUuid=response.data.customeruuid;
						this.addForm.customerName=response.data.customername;
						this.addForm.name=response.data.name;
						this.addForm.instUuid=response.data.inst_uuid;
						this.addForm.instname=response.data.instname;
						this.repaireReadonly=true;
						//await this.newSearchCustomerChange(response.data.customeruuid,'form')
						await this.getFormInstTree(response.data.customeruuid,response.data.province,response.data.city,response.data.district);
					}else{
						this.addForm.locations=''
						this.addForm.location=[];
						this.addForm.province='';
						this.addForm.city='';
						this.addForm.district='';
						this.addForm.customerUuid='';
						this.addForm.customerName='';
						this.addForm.name='';
						this.addForm.instUuid='';
						this.addForm.instname='';
						this.repaireReadonly=false;
					}
				}else{
					this.$Notice.error({
						title: '请求出错',
						desc:response.msg
					});
				}
			}
		},
		
		async repaireCascaderChange(value,selectedData){
			if(!!value){
				this.addForm.province=value[0];
				this.addForm.city=value[1];
				this.addForm.district=value[2];
				//更新客户列表，如果客户已选则清空
				if(this.user_type!=='01'){
				let res= await getCustomerListByLocation(value[0],value[1],value[2]);
				let response=res.data;
					if(response.code===200){
						this.customerList=response.data;
						this.addForm.customerUuid='';
					}else{
						this.$Notice.error({
							title: '请求出错',
							desc:response.msg
						});
					}
				}else{
					//this.newSearchCustomerChange(this.userUuid,'form')
					this.getFormInstTree(this.userUuid,value[0],value[1],value[2])
				}
			}else{
				this.addForm.province='';
				this.addForm.city='';
				this.addForm.district='';
				this.customerList=[];
			}
		},
		async formCustomerChange(value){
			//await this.newSearchCustomerChange(value,'form')
			this.getFormInstTree(value,this.addForm.province,this.addForm.city,this.addForm.district);
		},
		async clickDistribuClick(){
			if(!this.distribuForm.candidate||this.distribuForm.candidate.length<=0){
				this.$Notice.error({
					desc:'请选择分配人员'
				})
			}else if(this.fpCanClick){
				this.fpCanClick=false;
				let res=await saveFPZJ(this.distribuForm);
				let response=res.data;
				if(response.code===200){
					this.distribuForm={
						uuid:'',
						candidate:'',
						content:''
					}
					this.modal_distribu_sheet=false;
					this.getTable();
				}else{
					this.$Notice.error({
						title: '请求出错',
						desc:response.msg
					});
				}
				this.fpCanClick=true;
			}
		},
		giveUpActionClick(){
			this.modal_distribu_sheet=false;
			this.distribuForm={
				uuid:'',
				candidate:'',
				content:''
			}
		},
		change(active){
			this.modal_repaire_progress=active;
		},
		distribuChange(active){
			this.modal_distribu_sheet=active;
		},
		handleClickAddForm(){
			// this.areasData=this.$store.state.user.areaData;
			this.modal_add_declaration_form=true;
		},
		handleClickVideoPlay(src){
			this.look_video_wrap.look_video=true;
			this.look_video_wrap.src=src;
		},
		handleClickPicLook(src){
			this.look_pic_wrap.look_pic=true;
			this.look_pic_wrap.src=src;
		},
		async getDetails(uuid){
			this.repaire_details=JSON.parse(JSON.stringify(this.empty_repaire_details));
			let res=await getRepaireDetails(uuid);
			let response=res.data;
			if(response.code===200){
				let {order_number,created,province,city,district,describe,faultType}=response.data.warning;
				let {name,mobile}=!!response.data.customer?response.data.customer:{name:'',mobile:''};
				let additional=response.data.board;
				let proName=!!response.data.pro?response.data.pro.name:'';
				let reason=!!response.data.reason?response.data.reason.content:'';
				let solve=!!response.data.solve?response.data.solve.content:'';
				let customername=response.data.customername;
				let equip=!!response.data.equip?response.data.equip.name:'';
				let attitude_score,skill_score,speed_score,content;
				let inst_name=response.data.instName;
				if(!!response.data.score&&!!response.data.score.attitude_score){
					attitude_score=response.data.score.attitude_score;
					skill_score=response.data.score.skill_score;
					speed_score=response.data.score.speed_score;
					content=response.data.score.content;
				}else{
					attitude_score=null;
					skill_score=null;
					speed_score=null;
					content=null;
				}
				let imageList=response.data.imageList;
				if(!imageList){
					imageList=[];
				}
				let video=response.data.video;
				
				let location=`${province} ${city}`;
				if(!!district){
					location=`${location} ${district}`
				}
				let startTime=created.slice(0,16);
				this.repaire_details={
					order_number,
					startTime,
					name,
					mobile,
					customername,
					location,
					inst_name,
					equip,
					describe,
					imageList,
					video,
					additional,
					proName,
					faultType,
					reason,
					solve,
					attitude_score,
					skill_score,
					speed_score,
					content
				}
				this.modal_repaire_detail=true;
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
			}
		},
		async download(){
			let res=await tableToExcelRepaire();
			let response=res.data;
			// if(response.code===200){

			// }else{
			//   this.$Notice.error({
			//     title: '下载失败',
			//     desc:response.msg
			//   })
			// }
		},
		async clickProgressBtn(uuid){
			let a=await this.getProgress(uuid);
			let b=await this.getProgressTime(uuid);
			this.modal_repaire_progress=true;
			if(a&&b){
				this.modal_repaire_progress=true;
			}
		},
		async getProgress(uuid){
			let res=await getRepaireProgress(uuid);
			let response=res.data;
			if(response.code===200){
				let list=response.data.rows.map(item=>{
					let a={};
					a.action=item.state_name;
					a.time=item.created.slice(0,16);
					a.time_consuming=item.used_time;
					a.operator=item.customer_name;
					a.remarks=!!item.content?item.content:'-';
					return a
				})
				this.repaire_progress_details.data=list;
				return true
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
				return false
			}
		},
		async getProgressTime(uuid){
			let res=await getRepaireProgressTotalTime(uuid);
			let response=res.data;
			if(response.code===200){
				this.repaire_progress_details.totalTime=response.data.time;
				return true
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
				return false
			}
		},
		async getpurchaseDatiles(uuid){
			let res=await getpurchase(uuid);
			let response=res.data;
			if(response.code===200){
				this.parts_Detailed.total=accounting.formatMoney(response.data.total,'',2,',');
				let detail=response.data.purchaseDetailList.map(item=>{
				return [
					{
					name:'确认时间',
					value:item.created.slice(0,16)
					},
					{
					name:'确认人',
					value:item.operName
					}
					,
					{
					name:'物品名称',
					value:item.name
					}
					,
					{
					name:'用途',
					value:item.purpose
					}
					,
					{
					name:'单价（元）',
					value:accounting.formatMoney(item.price,'',2,',')
					}
					,
					{
					name:'数量',
					value:item.count
					},
					{
					name:'总价（元）',
					value:accounting.formatMoney(item.total_price,'',2,',')
					}
				];
			
			});
		
				this.parts_Detailed.detail=detail;
				this.modal_parts_Detailed=true;
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
				return false
			}
		} ,
		async fpModal(uuid,inst_uuid){
		
			if(await this.getFPZJRecords(uuid)&& await this.getFPZJproslist(uuid,inst_uuid)){
				this.modal_distribu_sheet=true;
			}
		},
		async getFPZJRecords(uuid){
			let res=await getRecords(uuid);
			let response=res.data;
			if(response.code===200){
				if(response.data.rows.length>0){
					this.distribu_sheet.records=response.data.rows.map(item=>{
						return {
							operator:item.ustomer_name,
							action:item.state_name,
							nextOperator:item.assignTo,
							time:item.created.slice(0,16),
							remarks:item.raw_content
						}
					})
				}else{
					this.distribu_sheet.records=[]
				}
				return true
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
				return false
			}
		},
		async getFPZJproslist(uuid,inst_uuid){
			let res=await getFPPros(uuid,inst_uuid);
			let response=res.data;
			if(response.code===200){
				let list=response.data.candidates_json;
				this.proList.list1=list.filter(item=>{
					if(item.class==='同城'){
						let dis=accounting.unformat(item.distance);
						let dw='m'
						if(dis>=1000){
							dis=dis/1000;
							dw='km'
						}
						dis=accounting.toFixed(dis,2);
						dis=accounting.formatNumber(dis,3,' ');
						item.distance=`${dis}${dw}`;
						return item
					}
				})
				this.proList.list2=list.filter(item=>{
					if(item.class==='异地'){
						let dis=accounting.unformat(item.distance);
						let dw='m'
						if(dis>=1000){
							dis=dis/1000;
							dw='km'
						}
						dis=accounting.toFixed(dis,2);
						dis=accounting.formatNumber(dis,3,' ');
						item.distance=`${dis}${dw}`;
						return item
					}
				})
				return true
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
				return false
			}
		},
		async clickrevokeReapire(uuid){
			let res=await revokeReapire(uuid);
			let response=res.data;
			if(response.code===200){
				this.$Notice.success({
					desc:'撤回成功'
				});
				this.getTable();
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
			}
		},
		async clickcompleteRepaire(uuid){
			let res=await completeRepaire(uuid);
			let response=res.data;
			if(response.code===200){
				this.$Notice.success({
					desc:'标记完成'
				});
				this.getTable();
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
			}
		},
		async clickcancleRepaire(uuid){
			let res=await cancleRepaire(uuid);
			let response=res.data;
			if(response.code===200){
				this.$Notice.success({
					desc:'撤销成功'
				});
				this.getTable();
			}else{
				this.$Notice.error({
					title: '请求出错',
					desc:response.msg
				});
			}
		},

	},
	watch:{
		modal_add_declaration_form:function(){
			if(!this.modal_add_declaration_form){
				this.resetAddform();
			}
		},
		modal_distribu_sheet:function(){
			if(!this.modal_distribu_sheet){
				this.distribuForm={
					uuid:'',
					candidate:'',
					content:''
				};
				this.proList={
					list1:[],
					list2:[]
				}
			}
		}
	},
	created(){
		this.init();
		this.getSelectInfo();
		this.btnp=util.bpower(this,this.btn);
		if(this.$route.params.pro_uuid){
			this.pro_uuid=this.$route.params.pro_uuid
		}
		this.formItem.warningOvertime=this.$route.query.state?this.$route.query.state:'全部';
		this.getTable();
	}
	}

	</script>
	<style lang='scss' >
	.ivu-date-picker{
	width:100%;
	}

	.detail-form{
	padding:15px 40px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	flex-wrap: wrap;
	border-bottom:1px solid #eee;
	&-item{
		width:40%;
		padding: 5px 0;
		label{
		color:rgb(49, 48, 48);
		}
	}
	.detail-img-video{
		padding:5px 0 5px 70px;
		position:relative;
		width:100%;
		span{
		position: absolute;
		top:5px;
		left:0;
		color:rgb(49, 48, 48);
		}
		.wrap{
		display:flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-items: center;
		
		img,video{
			width:100px;
			height:100px;
			margin-bottom:10px;
			cursor: pointer;
		}
		}

	}
	}
	.detail-supplement{
	padding:10px 0 10px 40px;
	&-item{
		padding:6px 0;
		border-bottom:1px solid #eee;
		.spokesman{
		display: flex;
		align-items: center;
		margin-bottom:5px;
		}
		.speech{
		padding-left:50px;
		padding-right:20px;
		}
	}
	}

	</style><!--  -->
